package com.ychs.controller.front;

import com.ychs.bean.Clazz;
import com.ychs.service.IClazzService;
import com.ychs.service.ISeatService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: 描述【】
 * Copyright: Copyright (c) 2018
 * Company: 英才汇硕信息技术有限公司
 *
 * @author tianchuanjie
 * @version 1.0
 * @created 2018/12/24 16:48
 */
@Controller
public class ClazzFrontController {
    private Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    private IClazzService clazzService;

    @Autowired
    private ISeatService seatService;

//    @Autowired
//    private ISeatService seatService;


    /**
     * @param storey  点击的楼层参数
     * @param request
     * @return
     */
    @GetMapping("/frontClazz")
    public String libraryClazzInfo(String storey, HttpServletRequest request) {

        //按照楼层查询教室数据
        List<Clazz> clazzList = clazzService.queryFloor(storey);

//        Clazz clazz  =new Clazz();//entity为实体类
//        clazz.setUseSeats(2);//将数据赋值给实体的属性a，依次类推
//        clazzList.add(clazz);


        for(Clazz clazz: clazzList){
            //
            String clazzName = clazz.getClazzName();
            logger.debug(clazzName);
            int result = seatService.selectUseSeats(clazzName);
            logger.debug(result);


            clazz.setUseSeats(result);
        }
        request.setAttribute("clazzList", clazzList);

//        Map<String, List> map = new HashMap<>();

//        for(Clazz clazz : clazzList){
//            String clazzName = clazz.getClazzName();
//            logger.debug("教室名称"+clazzName);
//            //查询到座位得到集合
//            List<Seat> seatList = seatService.queryByClazzName(clazzName);
//          //  map.put(clazzName,seatList);
//         //   request.setAttribute("seatList",map);
//            int i=0;
//            for(Seat seat:seatList){
//
//                //获取教室的状态
//                int seatStatus = seat.getSeatStatus();
//                //教室剩余的座位数
//                if(seatStatus==0){
//                    i=i+1;
//                }
//                logger.debug("座位的状态："+seatStatus);
//            }
//            request.setAttribute("seatList",seatList);
//            logger.debug("剩余的教室数目是"+i);
//            logger.debug("教室中的座位数"+seatList.size());
//        }
//
//     //   logger.debug("aaaaaaaaaaaa"+map.keySet());
//        logger.debug("教室的list"+clazzList.size());
        return "/front/clazz";
    }
}
